package cn.keniykey.mc.landterritory.command.only;

import java.util.regex.Pattern;

import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import cn.keniykey.mc.landterritory.command.CommandUtil;
import cn.keniykey.mc.landterritory.config.LanguageManager;
import cn.keniykey.mc.landterritory.land.LandManager;
import cn.keniykey.mc.landterritory.land.LandTransferUtil;
import cn.keniykey.mc.landterritory.land.api.Land;

public final class CommandGo implements CommandExecutor{

	@Override
	public boolean onCommand(CommandSender sender, Command cmd, String arg, String[] args) {
		if (!(sender instanceof Player)) {//告诉它不是人（滑稽）
			CommandUtil.sendMustPlayer(sender);
			return true;
		}
		final Player player = (Player)sender;
		if (args.length < 1) {
			player.sendMessage(LanguageManager.getChatLang(1201100));
			return true;
		}
		final Land land; //领地详情
		final int lang;
		if (Pattern.matches("^\\d+$", args[0])) {
			lang = 1202000;
			land = LandManager.getLandManager().getLand(Long.valueOf(args[0]));
		}else {
			lang = 1202001;
			land = LandManager.getLandManager().getLand(args[0]);
		}
		if(land == null) {
			player.sendMessage(LanguageManager.getChatLang(lang, args[0]));
			return true;
		}
		LandTransferUtil.transferLand(player, land, true, true);
		return true;
	}
}
